.jenkins-search-container {
  position: relative;
}

.jenkins-search {
  --search-bar-height: 2.375rem;

  position: relative;

  &__input {
    appearance: none;
    background: var(--item-background--hover);
    border: none;
    outline: none;
    border-radius: 0.625rem;
    width: 100%;
    margin: 0;
    padding: 0 0.5rem 0 var(--search-bar-height);
    line-height: 1;
    box-shadow:
      0 0 0 2px transparent,
      0 0 0 12px transparent;
    transition: var(--standard-transition);
    height: var(--search-bar-height);

    &::placeholder {
      color: var(--text-color-secondary);
    }

    // Safari adds unwanted padding - let's remove it
    &::-webkit-search-decoration {
      -webkit-appearance: none;
    }

    &::-webkit-search-cancel-button {
      -webkit-appearance: none;
      height: 45%;
      min-height: 1.1rem;
      aspect-ratio: 1;
      margin-right: 0.2rem;
      background: currentColor;
      mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm75.31 260.69a16 16 0 11-22.62 22.62L256 278.63l-52.69 52.68a16 16 0 01-22.62-22.62L233.37 256l-52.68-52.69a16 16 0 0122.62-22.62L256 233.37l52.69-52.68a16 16 0 0122.62 22.62L278.63 256z'/%3E%3C/svg%3E");
      mask-size: contain;
      mask-repeat: no-repeat;
      opacity: 0;
      pointer-events: none;
      transform: scale(0.8);
      transition: var(--standard-transition);
      cursor: pointer;

      &:hover {
        opacity: 0.75 !important;
      }

      &:active {
        opacity: 1 !important;
      }
    }

    &:not(:disabled) {
      &:hover {
        background: var(--item-background--active);
      }

      &:active,
      &:focus {
        outline: none;
        background: var(--item-background--active);
        box-shadow:
          0 0 0 2px var(--focus-input-border),
          0 0 0 7px var(--focus-input-glow);

        &::-webkit-search-cancel-button {
          opacity: 0.5;
          pointer-events: all;
          transform: scale(1);
        }
      }
    }

    &:disabled {
      cursor: not-allowed;
    }
  }

  &__icon {
    position: absolute;
    aspect-ratio: 1 / 1;
    top: 0;
    left: 0;
    bottom: 0;
    display: grid;
    pointer-events: none;

    svg {
      width: 45%;
      height: 45%;
      max-width: 1.1rem;
      max-height: 1.1rem;
      grid-column-start: 1;
      grid-row-start: 1;
      place-self: center center;
      transition: var(--standard-transition);
    }

    &::before,
    &::after {
      content: "";
      width: 0;
      height: 0;
      max-width: 1.1rem;
      max-height: 1.1rem;
      border: 0.125rem solid currentColor;
      border-radius: 100%;
      transition: var(--standard-transition);
      grid-column-start: 1;
      grid-row-start: 1;
      place-self: center center;
      opacity: 0;
    }

    &::after {
      clip-path: inset(0 0 50% 50%);
      transition: var(--standard-transition);
      animation: loading-spinner 1s infinite linear;

      @media (prefers-reduced-motion) {
        animation-duration: 2s;
      }
    }
  }

  .jenkins-keyboard-shortcut {
    position: absolute;
    top: calc(50% - 0.6875rem);
    right: 0.5rem;
    min-width: 1.375rem;
    min-height: 1.375rem;
    padding: 0;
    color: var(--text-color-secondary);
  }

  &--loading {
    .jenkins-search__icon {
      svg {
        opacity: 0;
        transform: scale(0);
      }

      &::before {
        opacity: 0.2;
        width: 45%;
        height: 45%;
      }

      &::after {
        opacity: 1;
        width: 45%;
        height: 45%;
      }
    }
  }

  &--app-bar {
    --search-bar-height: 3rem;

    max-width: 50vw;
    margin-block: -6px;

    .jenkins-keyboard-shortcut {
      right: 0.8125rem;
    }

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: 10px;
      z-index: -1;
      backdrop-filter: blur(20px);
      box-shadow: 0 0 var(--section-padding) var(--background);

      @supports not (backdrop-filter: blur(20px)) {
        background: var(--background);
      }
    }
  }

  &:focus-within {
    .jenkins-search__icon {
      fill: var(--focus-input-border);
    }

    .jenkins-keyboard-shortcut {
      opacity: 0;
      transform: scale(0.9);
      pointer-events: none;
    }
  }

  &--disabled {
    color: var(--text-color-secondary);
    opacity: 0.5;

    .jenkins-keyboard-shortcut {
      display: none;
    }
  }
}

.jenkins-search__results-container {
  position: absolute;
  width: 100%;
  border-radius: 1rem;
  box-shadow: var(--dropdown-box-shadow);
  overflow: hidden;
  z-index: 10;
  height: 1px; // Setting to 0 caused the items not to render initially in Chrome
  opacity: 0;
  transition: var(--standard-transition);
  backdrop-filter: var(--dropdown-backdrop-filter);
  visibility: collapse;
  scale: 95%;
  translate: 0 -0.3125rem;
  will-change: height, scale, opacity;

  &--visible {
    opacity: 1;
    scale: 100%;
    visibility: visible;
    translate: 0 0.3125rem;
  }

  a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.5rem 0.7rem;
    font-size: 0.875rem;
    border-radius: 10px;
    color: var(--text-color);
    font-weight: 500;
    text-decoration: none;
    z-index: 0;
    line-height: 1;
    min-height: 2.25rem;
    transition: background var(--standard-transition);

    div {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 1.125rem;
      height: 1.125rem;

      svg,
      img {
        width: 100%;
        height: 100%;
      }
    }

    &::before,
    &::after {
      position: absolute;
      content: "";
      inset: 0;
      z-index: -1;
      border-radius: 10px;
      transition: var(--standard-transition);
      pointer-events: none;
    }

    &::before {
      background-color: transparent;
    }

    &::after {
      box-shadow: 0 0 0 0.66rem transparent;
    }

    &:hover,
    &:focus {
      &::before {
        background-color: var(--item-background--hover);
      }
    }

    &:active,
    &:focus {
      outline: none !important;
      z-index: 1;

      &::before {
        background-color: var(--item-background--active);
      }

      &::after {
        box-shadow: 0 0 0 0.33rem var(--item-box-shadow--focus);
      }
    }

    &:focus-visible {
      &::after {
        box-shadow: 0 0 0 0.33rem var(--text-color);
      }
    }
  }

  .jenkins-search__results {
    position: relative;
    display: flex;
    justify-content: flex-start;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.4rem;

    & > div {
      position: relative;
      margin-top: -0.25rem;

      a {
        padding-left: 2.6rem;
        color: var(--text-color-secondary);
      }

      &::before {
        content: "";
        position: absolute;
        top: 0.4rem;
        left: 1.1rem + 0.625rem;
        bottom: 0.3rem;
        width: 0.125rem;
        background: currentColor;
        border-radius: 100vmax;
        opacity: 0.05;
      }

      &:empty {
        display: none;
      }
    }
  }

  &:hover {
    .jenkins-search__results-item--selected {
      background: transparent;
    }
  }
}

.jenkins-search__results-item--selected {
  background: var(--item-background--hover);
  animation: pulse 1s ease-in-out forwards;

  @keyframes pulse {
    50% {
      background: var(--item-background--active);
    }
  }
}

.jenkins-search__results__no-results-label {
  text-align: center;
  margin: 2rem;
  padding: 0;
  color: var(--text-color-secondary);
  font-weight: 500;
}
